package com.github.postsanf.yinian.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.github.postsanf.yinian.BaseActivity;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.ShopCarOrderListAdapter1;
import com.github.postsanf.yinian.adapter.ShopCarOrderListAdapter2;
import com.github.postsanf.yinian.adapter.ShopCarOrderListAdapter3;
import com.github.postsanf.yinian.adapter.ShopCarOrderListAdapter4;
import com.github.postsanf.yinian.bean.YNAddress;
import com.github.postsanf.yinian.bean.YNShopCar;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.github.postsanf.yinian.constants.CommonConstants;
import com.github.postsanf.yinian.utils.BigDecimalUtil;
import com.github.postsanf.yinian.utils.ReqUtils;
import com.github.postsanf.yinian.utils.StringUtils;
import com.github.postsanf.yinian.widget.MyListView;
import com.litesuits.http.exception.HttpException;
import com.litesuits.http.listener.HttpListener;
import com.litesuits.http.request.StringRequest;
import com.litesuits.http.request.param.HttpMethods;
import com.litesuits.http.response.Response;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import cn.beecloud.BCPay;
import cn.beecloud.async.BCCallback;
import cn.beecloud.async.BCResult;
import cn.beecloud.entity.BCPayResult;

public class ShopCarOrderActivity extends BaseActivity implements View.OnClickListener {
    private List<YNShopCar> ynShopCarList1 = new ArrayList<>();
    private List<YNShopCar> ynShopCarList2 = new ArrayList<>();
    private List<YNShopCar> ynShopCarList3 = new ArrayList<>();
    private List<YNShopCar> ynShopCarList4 = new ArrayList<>();
    private MyListView myListView1;
    private MyListView myListView2;
    private MyListView myListView3;
    private MyListView myListView4;
    private ShopCarOrderListAdapter1 shopCarOrderListAdapter1;
    private ShopCarOrderListAdapter2 shopCarOrderListAdapter2;
    private ShopCarOrderListAdapter3 shopCarOrderListAdapter3;
    private ShopCarOrderListAdapter4 shopCarOrderListAdapter4;
    private TextView order_name;
    private TextView order_telphone;
    private TextView order_address;
    private TextView order_address_tip;
    private RelativeLayout order_head;
    private LinearLayout order_address_info;
    private RelativeLayout order_pay_post;
    private TextView post_switch_content;
    private TextView order_num_total;
    private TextView order_youhui_total;
    private TextView now_pay;
    private ToggleButton post_switch1;
    private String itemInfoStr;
    private RelativeLayout ll_voice, ll_lomo, ll_photo, ll_draw;
    private RelativeLayout rl_voice_youhui, rl_lomo_youhui, rl_photo_youhui, rl_draw_youhui;
    private TextView rl_voice_youhui_price, rl_lomo_youhui_price, rl_photo_youhui_price, rl_draw_youhui_price;
    private View ll_voice_kong, ll_lomo_kong, ll_photo_kong, ll_draw_kong;
    private int addressID = 0;
    private String hejiPrice;
    private String youhuitotal;
    private String ebOrderID;
    private String postPrice = "5";
    private Handler myHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    shopCarOrderListAdapter1.notifyDataSetChanged();
                    if (ynShopCarList1.size() > 0) {
                        ll_voice.setVisibility(View.VISIBLE);
                        ll_voice_kong.setVisibility(View.VISIBLE);
                    } else {
                        ll_voice.setVisibility(View.GONE);
                        ll_voice_kong.setVisibility(View.GONE);
                    }
                    break;
                case 2:
                    shopCarOrderListAdapter2.notifyDataSetChanged();
                    if (ynShopCarList2.size() > 0) {
                        ll_lomo.setVisibility(View.VISIBLE);
                        ll_lomo_kong.setVisibility(View.VISIBLE);
                    } else {
                        ll_lomo.setVisibility(View.GONE);
                        ll_lomo_kong.setVisibility(View.GONE);
                    }
                    break;
                case 3:
                    shopCarOrderListAdapter3.notifyDataSetChanged();
                    if (ynShopCarList3.size() > 0) {
                        ll_photo.setVisibility(View.VISIBLE);
                        ll_photo_kong.setVisibility(View.VISIBLE);
                    } else {
                        ll_photo.setVisibility(View.GONE);
                        ll_photo_kong.setVisibility(View.GONE);
                    }
                    break;
                case 4:
                    shopCarOrderListAdapter4.notifyDataSetChanged();
                    if (ynShopCarList4.size() > 0) {
                        ll_draw.setVisibility(View.VISIBLE);
                        ll_draw_kong.setVisibility(View.VISIBLE);
                    } else {
                        ll_draw.setVisibility(View.GONE);
                        ll_draw_kong.setVisibility(View.GONE);
                    }
                    break;
                case 5:
                    if (ynShopCarList1.size() > 0 && ynShopCarList2.size() == 0 && ynShopCarList3.size() == 0 && ynShopCarList4.size() == 0) {
                        order_pay_post.setVisibility(View.VISIBLE);
                    } else {
                        order_pay_post.setVisibility(View.GONE);
                    }
                    break;
                case 6:
                    youhuitotal = BigDecimal.ZERO.add(new BigDecimal(couponPrice1)).add(new BigDecimal(couponPrice2)).add(new BigDecimal(couponPrice3)).add(new BigDecimal(couponPrice4)).toString();
                    hejiPrice = BigDecimalUtil.sub(hejiPrice, youhuitotal);
                    order_num_total.setText("¥" + hejiPrice);
                    order_youhui_total.setText("（已折扣" + youhuitotal + "元）");
                    break;
                case 99:
                    showToast(toastMsg);
                    break;
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopcarorder);
        registerBoradcastReceiver();
        initView();
        hejiPrice = getIntent().getStringExtra("hejiPrice");
        order_num_total.setText("¥" + hejiPrice);
        initData();
    }

    private void initData() {
        JSONArray data = new JSONArray();
        JSONArray jsonArray1 = new JSONArray();
        JSONArray jsonArray2 = new JSONArray();
        JSONArray jsonArray3 = new JSONArray();
        JSONArray jsonArray4 = new JSONArray();
        try {
            for (int i = 0; i < ShopCarListActivity.ynShopCarClearAll.size(); i++) {
                YNShopCar ynShopCar = ShopCarListActivity.ynShopCarClearAll.get(i);
                if (ynShopCar.getEbGoodsID() == 1) {
                    JSONObject itemInfo = new JSONObject();
                    itemInfo.put("num", ynShopCar.getCartItemNum());
                    itemInfo.put("itemID", ynShopCar.getCartItemID());
                    jsonArray1.put(itemInfo);
                    ynShopCarList1.add(ynShopCar);
                } else if (ynShopCar.getEbGoodsID() == 2) {
                    JSONObject itemInfo = new JSONObject();
                    itemInfo.put("num", ynShopCar.getCartItemNum());
                    itemInfo.put("itemID", ynShopCar.getCartItemID());
                    jsonArray2.put(itemInfo);
                    ynShopCarList2.add(ynShopCar);
                } else if (ynShopCar.getEbGoodsID() == 3) {
                    JSONObject itemInfo = new JSONObject();
                    itemInfo.put("num", ynShopCar.getCartItemNum());
                    itemInfo.put("itemID", ynShopCar.getCartItemID());
                    jsonArray3.put(itemInfo);
                    ynShopCarList3.add(ynShopCar);
                } else if (ynShopCar.getEbGoodsID() == 4) {
                    JSONObject itemInfo = new JSONObject();
                    itemInfo.put("num", ynShopCar.getCartItemNum());
                    itemInfo.put("itemID", ynShopCar.getCartItemID());
                    jsonArray4.put(itemInfo);
                    ynShopCarList4.add(ynShopCar);
                }
            }
            JSONObject ebGoods1 = new JSONObject();
            ebGoods1.put("ebGoodsID", 1);
            ebGoods1.put("itemInfo", jsonArray1);
            if (jsonArray1.length() > 0)
                data.put(ebGoods1);
            JSONObject ebGoods2 = new JSONObject();
            ebGoods2.put("ebGoodsID", 2);
            ebGoods2.put("itemInfo", jsonArray2);
            ebGoods1.put("itemInfo", jsonArray1);
            if (jsonArray2.length() > 0)
                data.put(ebGoods2);
            JSONObject ebGoods3 = new JSONObject();
            ebGoods3.put("ebGoodsID", 3);
            ebGoods3.put("itemInfo", jsonArray3);
            if (jsonArray3.length() > 0)
                data.put(ebGoods3);
            JSONObject ebGoods4 = new JSONObject();
            ebGoods4.put("ebGoodsID", 4);
            ebGoods4.put("itemInfo", jsonArray4);
            if (jsonArray4.length() > 0)
                data.put(ebGoods4);
            itemInfoStr = new JSONObject().put("data", data).toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        myHandler.sendEmptyMessage(1);
        myHandler.sendEmptyMessage(2);
        myHandler.sendEmptyMessage(3);
        myHandler.sendEmptyMessage(4);
        myHandler.sendEmptyMessage(5);
        showShopReceiverAddress(itemInfoStr);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(mListReceiver);
    }

    private void registerBoradcastReceiver() {
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(ACTIONs.actionUpdateShopReceiver);
        myIntentFilter.addAction(ACTIONs.actionUpdateShopAddress);
        registerReceiver(mListReceiver, myIntentFilter);
    }

    BroadcastReceiver mListReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            switch (action) {
                case ACTIONs.actionUpdateShopReceiver:
                    if (intent != null) {
                        YNAddress ynAddress = (YNAddress) intent.getSerializableExtra("YNAddress");
                        if (ynAddress != null) {
                            order_address_info.setVisibility(View.VISIBLE);
                            order_address.setVisibility(View.VISIBLE);
                            order_address_tip.setVisibility(View.GONE);
                            addressID = ynAddress.getAddressID();
                            order_name.setText(ynAddress.getAddressReceiver());
                            order_address.setText(ynAddress.getAddressDetail());
                            order_telphone.setText(ynAddress.getAddressPhoneNumber());
                            ChangeDefaultAddress(String.valueOf(ynAddress.getAddressID()));
                        } else {
                            order_address_info.setVisibility(View.GONE);
                            order_address.setVisibility(View.GONE);
                            order_address_tip.setVisibility(View.VISIBLE);
                        }
                    }
                    break;
                case ACTIONs.actionUpdateShopAddress:
                    if (intent != null) {
                        int intentAddressid = intent.getIntExtra("addressid", 0);
                        if (intentAddressid == addressID) {
                            order_address_info.setVisibility(View.GONE);
                            order_address.setVisibility(View.GONE);
                            order_address_tip.setVisibility(View.VISIBLE);
                        }
                    }
                    break;
            }
        }
    };


    private void initView() {
        findViewById(R.id.shopcarorder_back).setOnClickListener(this);
        order_name = (TextView) findViewById(R.id.order_name);
        order_telphone = (TextView) findViewById(R.id.order_telphone);
        order_address = (TextView) findViewById(R.id.order_address);
        order_address_tip = (TextView) findViewById(R.id.order_address_tip);
        order_head = (RelativeLayout) findViewById(R.id.order_head);
        order_address_info = (LinearLayout) findViewById(R.id.order_address_info);
        order_head.setOnClickListener(this);
        order_pay_post = (RelativeLayout) findViewById(R.id.order_pay_post);
        post_switch_content = (TextView) findViewById(R.id.post_switch_content);
        order_num_total = (TextView) findViewById(R.id.order_num_total);
        order_youhui_total = (TextView) findViewById(R.id.order_youhui_total);
        now_pay = (TextView) findViewById(R.id.now_pay);
        now_pay.setOnClickListener(this);
        post_switch1 = (ToggleButton) findViewById(R.id.post_switch1);
        post_switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                post_switch1.setChecked(isChecked);
                if (post_switch1.isChecked()) {
                    post_switch_content.setText("快递（" + postPrice + "元）");
                    order_youhui_total.setText("（已折扣" + youhuitotal + "元）");
                    hejiPrice = BigDecimalUtil.add(hejiPrice, postPrice);
                    order_num_total.setText("¥" + hejiPrice);
                } else {
                    post_switch_content.setText("平邮");
                    order_youhui_total.setText("（已折扣" + youhuitotal + "元）");
                    hejiPrice = BigDecimalUtil.sub(hejiPrice, postPrice);
                    order_num_total.setText("¥" + hejiPrice);
                }
            }
        });
        myListView1 = (MyListView) findViewById(R.id.list1);
        myListView2 = (MyListView) findViewById(R.id.list2);
        myListView3 = (MyListView) findViewById(R.id.list3);
        myListView4 = (MyListView) findViewById(R.id.list4);
        shopCarOrderListAdapter1 = new ShopCarOrderListAdapter1(ShopCarOrderActivity.this, ynShopCarList1);
        shopCarOrderListAdapter2 = new ShopCarOrderListAdapter2(ShopCarOrderActivity.this, ynShopCarList2);
        shopCarOrderListAdapter3 = new ShopCarOrderListAdapter3(ShopCarOrderActivity.this, ynShopCarList3);
        shopCarOrderListAdapter4 = new ShopCarOrderListAdapter4(ShopCarOrderActivity.this, ynShopCarList4);
        myListView1.setAdapter(shopCarOrderListAdapter1);
        myListView2.setAdapter(shopCarOrderListAdapter2);
        myListView3.setAdapter(shopCarOrderListAdapter3);
        myListView4.setAdapter(shopCarOrderListAdapter4);
        ll_voice = (RelativeLayout) findViewById(R.id.ll_voice);
        rl_voice_youhui = (RelativeLayout) findViewById(R.id.rl_voice_youhui);
        rl_voice_youhui_price = (TextView) findViewById(R.id.rl_voice_youhui_price);
        ll_voice_kong = (View) findViewById(R.id.ll_voice_kong);
        ll_lomo = (RelativeLayout) findViewById(R.id.ll_lomo);
        rl_lomo_youhui = (RelativeLayout) findViewById(R.id.rl_lomo_youhui);
        rl_lomo_youhui_price = (TextView) findViewById(R.id.rl_lomo_youhui_price);
        ll_lomo_kong = (View) findViewById(R.id.ll_lomo_kong);
        ll_photo = (RelativeLayout) findViewById(R.id.ll_photo);
        rl_photo_youhui = (RelativeLayout) findViewById(R.id.rl_photo_youhui);
        rl_photo_youhui_price = (TextView) findViewById(R.id.rl_photo_youhui_price);
        ll_photo_kong = (View) findViewById(R.id.ll_photo_kong);
        ll_draw = (RelativeLayout) findViewById(R.id.ll_draw);
        ll_draw_kong = (View) findViewById(R.id.ll_draw_kong);
        rl_draw_youhui = (RelativeLayout) findViewById(R.id.rl_draw_youhui);
        rl_draw_youhui_price = (TextView) findViewById(R.id.rl_draw_youhui_price);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.shopcarorder_back:
                finish();
                break;
            case R.id.order_head:
                startActivity(new Intent(ShopCarOrderActivity.this, ShopAddressListActivity.class));
                break;
            case R.id.now_pay:
                if (addressID == 0) {
                    showToast("请编辑地址");
                    return;
                }
                if (StringUtils.isEmpty(hejiPrice)) {
                    showToast("价格为空");
                    return;
                }
                doCashComplete();
                break;
        }
    }

    private String couponPrice1 = "0.0";
    private String couponPrice2 = "0.0";
    private String couponPrice3 = "0.0";
    private String couponPrice4 = "0.0";

    private void showShopReceiverAddress(String itemInfoStr) {
//        Log.i("xjs", "itemInfoStr==>" + itemInfoStr);
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put("userid", String.valueOf(application.getCurID()));
        mParam.put("itemInfo", itemInfoStr);
        StringRequest req = new StringRequest(getString(R.string.SHOP_URL) + getString(R.string.ynGetInfoBeforePay))
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                                     @Override
                                     public void onSuccess(String s, Response<String> response) {
                                         try {
                                             JSONObject sjson = new JSONObject(s);
                                             if (ReqUtils.isSuccess(String.valueOf(sjson.optInt("code")))) {
                                                 JSONArray data = sjson.optJSONArray("data");
                                                 if (data.optJSONObject(0).optJSONArray("address") != null && data.optJSONObject(0).optJSONArray("address").length() > 0) {
                                                     JSONObject address = data.optJSONObject(0).optJSONArray("address").optJSONObject(0);
                                                     order_address_tip.setVisibility(View.GONE);
                                                     order_address_info.setVisibility(View.VISIBLE);
                                                     order_address.setVisibility(View.VISIBLE);
                                                     if (address != null) {
                                                         String addressReceiver = address.optString("addressReceiver");
                                                         order_name.setText(addressReceiver);
                                                         String addressPhoneNumber = address.optString("addressPhoneNumber");
                                                         order_telphone.setText(addressPhoneNumber);
                                                         String addressDetail = address.optString("addressDetail");
                                                         order_address.setText(addressDetail);
                                                         addressID = address.optInt("addressID");
                                                     }
                                                 } else {
                                                     order_address_tip.setVisibility(View.VISIBLE);
                                                     order_address_info.setVisibility(View.GONE);
                                                     order_address.setVisibility(View.GONE);
                                                 }
                                                 if (data.optJSONObject(0).optJSONArray("coupon") != null && data.optJSONObject(0).optJSONArray("coupon").length() > 0) {
                                                     JSONArray couponArray = data.optJSONObject(0).optJSONArray("coupon");
                                                     for (int i = 0; i < couponArray.length(); i++) {
                                                         JSONObject coupon = data.optJSONObject(0).optJSONArray("coupon").optJSONObject(i);
                                                         if (coupon.optInt("goodsID") == 1) {
                                                             if (coupon.optDouble("totalCouponPrice") > 0) {
                                                                 couponPrice1 = String.valueOf(coupon.optDouble("totalCouponPrice"));
                                                                 rl_voice_youhui.setVisibility(View.VISIBLE);
                                                                 rl_voice_youhui_price.setText("¥" + couponPrice1 + "专属优惠卷");
                                                             }
                                                         } else if (coupon.optInt("goodsID") == 2) {
                                                             if (coupon.optDouble("totalCouponPrice") > 0) {
                                                                 couponPrice2 = String.valueOf(coupon.optDouble("totalCouponPrice"));
                                                                 rl_lomo_youhui.setVisibility(View.VISIBLE);
                                                                 rl_lomo_youhui_price.setText("¥" + couponPrice2 + "专属优惠卷");
                                                             }
                                                         } else if (coupon.optInt("goodsID") == 3) {
                                                             if (coupon.optDouble("totalCouponPrice") > 0) {
                                                                 couponPrice3 = String.valueOf(coupon.optDouble("totalCouponPrice"));
                                                                 rl_photo_youhui.setVisibility(View.VISIBLE);
                                                                 rl_photo_youhui_price.setText("¥" + couponPrice3 + "专属优惠卷");
                                                             }
                                                         } else if (coupon.optInt("goodsID") == 4) {
                                                             if (coupon.optDouble("totalCouponPrice") > 0) {
                                                                 couponPrice4 = String.valueOf(coupon.optDouble("totalCouponPrice"));
                                                                 rl_draw_youhui.setVisibility(View.VISIBLE);
                                                                 rl_draw_youhui_price.setText("¥" + couponPrice4 + "专属优惠卷");
                                                             }
                                                         }
                                                     }
                                                     myHandler.sendEmptyMessage(6);
                                                 }
                                                 if (data.optJSONObject(0).optJSONArray("postFee") != null && data.optJSONObject(0).optJSONArray("postFee").length() > 0) {
                                                     JSONObject postFee = data.optJSONObject(0).optJSONArray("postFee").optJSONObject(0);
                                                     postPrice = postFee.optString("postCardFee");

                                                 }
                                             }
                                         } catch (JSONException e) {
                                             e.printStackTrace();
                                         }

                                     }

                                     @Override
                                     public void onFailure(HttpException e, Response<String> response) {
                                         showToast(CommonConstants.YN_NET_LINK);
                                     }
                                 }

                );
        liteHttp.executeAsync(req);
    }

    // 友盟统计
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);

    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }


    private void ChangeDefaultAddress(String addressID) {
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put("userid", String.valueOf(application.getCurID()));
        mParam.put("addressID", addressID);
        StringRequest req = new StringRequest(getString(R.string.SHOP_URL) + getString(R.string.ynChangeDefaultAddress))
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
                        showToast(CommonConstants.YN_NET_LINK);
                    }
                });
        liteHttp.executeAsync(req);
    }


    private void doCashComplete() {
        LinkedHashMap<String, String> mParam = new LinkedHashMap<>();
        mParam.put("userid", String.valueOf(application.getCurID()));
        mParam.put("addressID", String.valueOf(addressID));
        mParam.put("itemInfo", itemInfoStr);
//        Log.i("xjs","userid==>"+application.getCurID());
//        Log.i("xjs","addressID==>"+addressID);
//        Log.i("xjs","itemInfoStr==>"+itemInfoStr);
        if (post_switch1.isChecked()) {
            mParam.put("isMail", "yes");
        } else {
            mParam.put("isMail", "no");
        }
        StringRequest req = new StringRequest(getString(R.string.SHOP_URL) + getString(R.string.ynBuyGoodsByCart))
                .setMethod(HttpMethods.Post)
                .setParamMap(mParam)
                .setHttpListener(new HttpListener<String>(true, false, true) {
                    @Override
                    public void onSuccess(String s, Response<String> response) {
                        try {
                            JSONObject resultOrder = new JSONObject(s.toString());
                            if (ReqUtils.isSuccess(resultOrder.optString("code"))) {
                                ebOrderID = resultOrder.optJSONArray("data").optJSONObject(0).optString("ebOrderID");
                                String ebOrderNumber = resultOrder.optJSONArray("data").optJSONObject(0).optString("ebOrderNumber");
                                HashMap<String, String> mapOptional = new HashMap<>();
                                mapOptional.put("userid", String.valueOf(application.getCurID()));
                                mapOptional.put("ebOrderID", ebOrderID);
                                mapOptional.put("ebOrderNumber", ebOrderNumber);
                                int zongPrice = BigDecimalUtil.multotal(hejiPrice, "100");
                                if (zongPrice <= 0) {
                                    showToast("价格有误，处理中！");
                                    return;
                                }
                                BCPay.getInstance(ShopCarOrderActivity.this).reqAliPaymentAsync("武汉市追忆那年网络科技有限公司", zongPrice,
                                        ebOrderNumber, mapOptional, callback);
                            } else {
                                showToast("异常");
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }

                    @Override
                    public void onFailure(HttpException e, Response<String> response) {
                        showToast(CommonConstants.YN_NET_LINK);
                    }
                });
        liteHttp.executeAsync(req);
    }

    private String toastMsg;
    BCCallback callback = new BCCallback() {
        @Override
        public void done(BCResult bcResult) {
            final BCPayResult bcPayResult = (BCPayResult) bcResult;
            String result = bcPayResult.getResult();
            Log.d("yuhao", "result=" + "支付失败, 原因: " + bcPayResult.getErrCode() +
                    " # " + bcPayResult.getErrMsg() +
                    " # " + bcPayResult.getDetailInfo());
            if (result.equals(BCPayResult.RESULT_SUCCESS)) {
                toastMsg = "用户支付成功";
                startActivity(new Intent(ShopCarOrderActivity.this, OrderListActivity.class).putExtra("ebOrderID", ebOrderID));
                sendBroadcast(new Intent(ACTIONs.actioncloseShopCarList));
                finish();
            } else if (result.equals(BCPayResult.RESULT_CANCEL)) {
                toastMsg = "用户取消支付";
            } else if (result.equals(BCPayResult.RESULT_FAIL)) {
                toastMsg = "支付失败, 原因: " + bcPayResult.getErrCode() +
                        " # " + bcPayResult.getErrMsg() +
                        " # " + bcPayResult.getDetailInfo();
            }
            myHandler.sendEmptyMessage(99);
            if (bcPayResult.getId() != null) {
                //你可以把这个id存到你的订单中，下次直接通过这个id查询订单
                Log.w(TAG, "bill id retrieved : " + bcPayResult.getId());
                //根据ID查询，此处只是演示如何通过id查询订单，并非支付必要部分
                // getBillInfoByID(bcPayResult.getId());
            }
        }
    };
}
